﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using GestionDeCinebox.Classes;

namespace GestionDeCinebox.UC
{
    /// <summary>
    /// Interaction logic for ucHome.xaml
    /// </summary>
    public partial class ucHome : UserControl
    {
        private MainWindow main;
        private DateTime choixDate = new DateTime();
        private DateTime choixTemps = new DateTime();
        public ucHome(MainWindow main)
        {
            InitializeComponent();
            this.main = main;
            LoadDate();
        }

        private void lstFilm_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Film f = lstFilm.SelectedItem as Film;
            Reservation r = new Reservation(f);
            r.Owner = Application.Current.MainWindow;
            r.Show();
        }

        void LoadDate()
        {
            DateTime today = DateTime.Today;
            cboDate.Items.Add(today.ToLongDateString());
            for (int i = 0; i < 6; i ++ )
            {
                today = today.AddDays(1);
                cboDate.Items.Add(today.ToLongDateString());
            }
        }

        private void cboDate_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            btnChercher.IsEnabled = true;
            choixDate = DateTime.Parse(cboDate.SelectedValue.ToString());
            CalculateDate();
        }

        private void cboTemps_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            btnChercher.IsEnabled = true;
            choixTemps = DateTime.Parse(((ComboBoxItem)cboTemps.SelectedItem).Content.ToString());
            CalculateDate();
        }

        void CalculateDate()
        {
            tbChoixDate.Text = choixDate.ToShortDateString() + " " + choixTemps.ToShortTimeString();
        }
    }
}
